package com.hxkj.controller;

import com.hxkj.domain.po.FriendlyLink;
import com.hxkj.service.FriendlyLinkService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * 友情链接控制器
 * <p>
 * Created by chenfangzhou on 2018/6/6.
 */
@RestController
@RequestMapping("/friendlink")
public class FriendlyLinkController {


    @Autowired
    private FriendlyLinkService friendlyLinkService;


    /**
     * 获取友情链接列表
     *
     * @param friendlyLink
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public Callable<ResultPageStruct<FriendlyLink>> getRoleList(@ModelAttribute FriendlyLink friendlyLink, @ModelAttribute PageTo pageParam) throws Exception {
        return () -> friendlyLinkService.getFriendlyLinkList(friendlyLink == null ? new FriendlyLink() : friendlyLink, pageParam);
    }


    /**
     * 获取单一链接
     *
     * @param friendlyLink
     * @return friendlyLink
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public Callable<ResultDataStruct<FriendlyLink>> getFriendlyLink(@ModelAttribute FriendlyLink friendlyLink) throws Exception {
        return () -> friendlyLinkService.getFriendlyLink(friendlyLink);
    }

    /**
     * 新增友情链接
     *
     * @param friendlyLink
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResultMessageStruct saveFriendlyLink(@ModelAttribute FriendlyLink friendlyLink) throws Exception {
        return friendlyLinkService.saveFriendlyLink(friendlyLink);
    }

    /**
     * 删除友情链接
     *
     * @param friendlyLink
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public ResultMessageStruct deleteFriendlyLink(@ModelAttribute FriendlyLink friendlyLink) throws Exception {
        return friendlyLinkService.deleteFriendlyLink(friendlyLink);
    }

    /**
     * 修改友情链接
     *
     * @param friendlyLink
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public ResultMessageStruct updateFriendlyLink(@ModelAttribute FriendlyLink friendlyLink) throws Exception {
        return friendlyLinkService.updateFriendlyLink(friendlyLink);
    }

}
